home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 386 / utility / speed_2.s < prev    next >
Text File  |  1985-11-19  |  8KB  |  195 lines

  1.  ; Program Name: SPEED_2.S
  2.  ; Version 1.003
  3.  
  4.  ; NOTE: This program is similar to SPEED_1.  The differences between the
  5.  ;       the two is that this one uses a different algorithm to process
  6.  ;       the command line, and it fetches the start time at a more appropriate
  7.  ;       place in the program.
  8.  
  9.  ; Assembly Instructions:
  10.  
  11.  ;     Assemble in "PC-relative" mode and save with a TTP extension. 
  12.  
  13.  ; Function:
  14.  
  15.  ;     Spawn a process and calculate the spawned program's load and execution
  16.  ; times.  Pause for a keypress before terminating.
  17.  
  18. release_excess_memory:
  19.  lea        program_end, a0     ; Put "end of program" address in A0.
  20.  movea.l    4(a7), a1           ; Put "basepage" address in A1.
  21.  movea.l    a1, a4              ; Copy to A4 for command line access.
  22.  trap       #6                  ; Calculate program size and release memory.
  23.  
  24.  ; NOTE: A local stack is not declared in PRG_5AP.TOS.  Because of the long
  25.  ;       string that is printed by that program, this program will bomb when
  26.  ;       it spawns PRG_5AP.TOS, if a local stack is not declared here.
  27.  
  28.  lea        stack, a7           ; Point A7 to this program's stack.
  29.  
  30.  ;           NOTE ABOUT THE COMMAND LINE PROCESSING ALGORITHM
  31.  
  32.  ;     Refer to figure 2.13 of chapter 2 for an image of a command line
  33.  ; that is stored in a program's basepage.  The first byte of the command
  34.  ; line is a count of the ASCII characters contained therein.  The second
  35.  ; byte is the first character in the command line.  The last character in
  36.  ; the command line is followed by the ASCII code for a carriage return; 
  37.  ; the carriage return is not included in the character count.
  38.  
  39.  ;     For program SPEED_2 we know that the command line character count
  40.  ; cannot exceed 12 characters = 12 bytes = 3 longwords.  Therefore, it
  41.  ; would be convenient if those 3 longwords could be transfered directly to
  42.  ; three data registers.  Unfortunately, the MC68000 will not permit the
  43.  ; movem instruction to transfer data which begins at an odd address.
  44.  
  45.  ;     Because of this restriction, it would be convenient if the operating
  46.  ; system stored the first command line character at an even address.
  47.  ; Unfortunately, it does not.  Therefore, we are forced to fetch 4 longwords
  48.  ; from the vicinity of the command line.  That's why we must use four data
  49.  ; registers instead of three.
  50.  
  51.  ;     To complicate things, the command line ASCII string will be corrupted
  52.  ; by the first byte in the first register, because it is the character count,
  53.  ; not a valid character.  So, when the data contained in the data registers
  54.  ; are transferred to a declared variable location, this byte must be stripped
  55.  ; from the command line ASCII string.
  56.  
  57.  ;     I accomplish this with no wasted time by declaring two variable
  58.  ; locations, input_line and program_name.  Since input_line is one byte in
  59.  ; length, and the first location for program_name immediately follows that
  60.  ; byte, when the contents of the data registers is moved to the location of
  61.  ; input_line, the variable program_name will point to the first character
  62.  ; of the command line ASCII string, as it should.
  63.  
  64.  ;     The carriage return at the end of the ASCII string is also transferred
  65.  ; to the 15 byte array addressed by program_name.  It must be overwritten by
  66.  ; a NULL so that the ASCII string is NULL terminated.  That is accomplished
  67.  ; fetching the command line character count as a byte length value, extending
  68.  ; it to word length and using the result in an operand that uses "address
  69.  ; register indirect with index" addressing.      
  70.   
  71. process_command_line:
  72.  lea        input_line, a3      ; Fetch location to contain command line.
  73.  lea        output_line, a5     ; A second location: for filename.
  74.  movem.l    $80(a4), d0-d3      ; Move 16 bytes of command line to 4 registers.
  75.  movem.l    d0-d3, (a3)         ; Move them to address "input_line".
  76.  movem.l    d0-d3, (a5)         ; Move them to address "output_line".
  77.  move.b     $80(a4), d0         ; Fetch command line ASCII character count.
  78.  ext.w      d0                  ; Extend to word for next instruction.
  79.  move.b     #0, 1(a3,d0.w)      ; Store a null at end of command line input.
  80.  move.b     #0, 1(a5,d0.w)      ; Same for filename buffer.
  81.  
  82. insert_filename_suffix:
  83.  move.b     #$44, -2(a5,d0.w)   ; Insert letter 'D'.
  84.  move.b     #$41, -1(a5,d0.w)   ; Insert letter 'A'.
  85.  move.b     #$54,  0(a5,d0.w)   ; Insert letter 'T'.
  86.  
  87. create_file:
  88.  move.w     #0, -(sp)           ; File attribute = read/write.
  89.  pea        filename            ; Will be name of spawned process + .DAT.
  90.  move.w     #$3C, -(sp)         ; Function = f_create = GEMDOS $3C.
  91.  trap       #1                  ; File handle is returned in D0.
  92.  addq.l     #8, sp
  93.  lea        file_handle, a0
  94.  move.w     d0, (a0)
  95.  
  96. redirect_output:                ; Exchange file handle with screen's handle.
  97.  move.w     file_handle, -(sp)  ; This is the disk file's handle.
  98.  move.w     #1, -(sp)           ; This is the video screen's handle.
  99.  move.w     #$46, -(sp)         ; Function = f_force = GEMDOS $46.
  100.  trap       #1
  101.  addq.l     #6, sp
  102.  
  103.  ; NOTE: In order to increase the accuracy of the start time, the stack is
  104.  ;       prepared for the spawning process, then, just before trap #1 is
  105.  ;       invoked, custom trap #3 is invoked and the start time is saved.
  106.  
  107. prepare_stack_for_load_and_execute_program:      
  108.  pea        environ_string
  109.  pea        command_line
  110.  pea        program_name
  111.  move.w     #0, -(sp)
  112.  move.w     #$4B, -(sp)         ; Function = GEMDOS $4B = p_exec.
  113.  
  114. get_start_time:
  115.  lea        start_time, a3      ; Fetch address of variable "start_time".
  116.  trap       #3                  ; Returns value of system clock in D0.
  117.  move.w     d0, (a3)            ; Save start time.
  118. load_and_execute_program:
  119.  trap       #1                 
  120.  move.w     d0, d3              ; Copy after-load value to D3 for calculation.
  121.  
  122. get_end_time:
  123.  trap       #3                  ; Returns value of system clock in D0.
  124.  move.w     d0, d5              ; Copy to D5 for calculation.
  125.  sub.w      d3, d5              ; Subtract after-load time from end time.
  126.  ext.l      d5                  ; Extend to 32 bits.
  127.  
  128. reposition_stack_pointer:
  129.  lea        $10(sp), sp        
  130.  
  131. get_drive:
  132.  move.w     #$19, -(sp)         ; Function = dgetdrv = GEMDOS $19.
  133.  trap       #1
  134.  addq.l     #2, sp
  135.  add.b      #'A', d0
  136.  lea        drive, a0
  137.  move.b     d0, (a0)
  138.  
  139. print_heading:
  140.  lea        heading, a0
  141.  bsr        print_string
  142.  lea        program_name, a0
  143.  bsr        print_string
  144. print_drive_for_spawned_program:
  145.  lea        drive_msg, a0
  146.  bsr        print_string
  147.  
  148. compute_load_time:
  149.  lea        load_time_msg, a0
  150.  bsr        print_string
  151.  lea        start_time, a3
  152.  sub.w      (a3), d3            ; Subtract start time from after-load time.
  153.  ext.l      d3                  ; Extent to 32 bits.
  154.  trap       #9                  ; See description in TRAPS.S.
  155.  
  156. close_file:
  157.  move.w     file_handle, -(sp)
  158.  move.w     #$3E, -(sp)         ; Function = fclose = GEMDOS $3E.
  159.  trap       #1
  160.  addq.l     #4, sp
  161.  
  162. terminate:
  163.  move.w     #0, -(sp)
  164.  trap       #1
  165.  
  166. print_string:                   ; Expects address of string to be in A0.
  167.  move.l     a0, -(sp)           ; Push address of string onto stack.
  168.  move.w     #9, -(sp)           ; Function = c_conws = GEMDOS $9.
  169.  trap       #1                  ; GEMDOS call
  170.  addq.l     #6, sp              ; Reset stack pointer to top of stack.
  171.  rts
  172.  
  173.  data
  174. heading:          dc.b $D,$A,"SPEED_2.TTP Execution Results",$D,$A
  175.                   dc.b       "for ",0
  176. drive_msg:        dc.b ", loaded from drive: "
  177. drive:            dc.b "A",$D,$A,0
  178. load_time_msg:    dc.b $D,$A,"  Load time:    ",0
  179. environ_string:   dc.b "TERM",0
  180. command_line:     dc.b 0
  181.  align
  182.  bss
  183. start_time:       ds.w    1
  184. file_handle:      ds.w    1
  185. input_line:       ds.b    1
  186. program_name:     ds.b   15     ; Program name buffer.
  187. output_line:      ds.b    1 
  188. filename:         ds.b   15     ; Filename buffer.
  189.                   ds.l   96     ; Program stack.
  190. stack:            ds.l    0     ; Address of program stack.
  191. program_end:      ds.l    0
  192.  end
  193.  
  194.  
  195.